// pages/populargoods/populargoods.js
var page = 1;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    popular_goods: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     page = 1, this.popular_goods(),getApp().page.onLoad(this, options);
  },
  popular_goods: function () {
    var a = this;
     getApp().core.showLoading({
      title: "加载中"
    }), getApp().request({
      url: getApp().api.default.popular_goods,
      data: {
        page: page
      },
      success: function (t) {
        console.log(t)
        if (0 === t.code) {
          var e = a.data.popular_goods;
          0 < t.data.list.length && (0 < e.length && (e = e.concat(t.data.list)), 0 === e.length && (e = t.data.list),
            page += 1), 0 === t.data.list.length && getApp().core.showToast({
              title: "没有更多啦",
              icon: "none"
            }), a.setData({
              popular_goods: e
            });
        }else if( 1 === t.code) {
          getApp().core.showToast({
            title: "没有更多啦",
            icon: "none"
          })
        }
      },
      complete: function () {
        getApp().core.hideLoading();
      }
    });
  },
  goods: function (e) {
    console.log(e)
    var goods_id = e.currentTarget.dataset.goods_id
    wx.navigateTo({
      url: '/pages/goods/goods?id=' + goods_id,
    })
  },
  onReachBottom: function (e) {
    // console.log('到底了+++++++', t)
    getApp().page.onReachBottom(this);
    this.popular_goods();
  }

})